﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DNASequencing.core.data;

namespace DNASequencing.core.Algorithms.rating
{
    class Graph2Rating : IRating
    {
        /// <summary>
        /// Number of all sequences.
        /// </summary>
        protected int _iSize;

        public Graph2Rating(int size)
        {
            _iSize = size;
        }

        /// <summary>
        /// Method used to rate oligonucleotide during sequencing process.
        /// Better rate is higher. This rating method gives priority to oligonucleotides with less followers.
        /// </summary>
        /// <param name="o">Oligonucleotide to be rated</param>
        /// <returns>Double that describe rating of oligonucleotide</returns>
        double IRating.rate(Oligonucleotide o)
        {
            if (o.used)
                return 0;

            o.rating = 0;

            int l = o.originalSequence.Length;
            for (int i = 0; i < o.next.Length; ++i)
                //if (!o.used)
                    o.rating += (o.originalSequence.Length - 1 - i) * (_iSize - o.next[i].Count) / _iSize;

            //System.Console.WriteLine(o.originalSequence + ": " + o.original.rating);
            o.rating += (l - o.error) * Math.Sqrt(l);

            return o.rating;
        }
    }
}
